import store from "@/store";
import {getToken} from "@/utils/auth";

export function initWebsocket(userId) {

    let ws = new WebSocket('ws://119.91.202.218:10000/uum-mq/websocket/' + userId + '/' + getToken());
    ws.onopen = () => {
        // Web Socket 已连接上，使用 send() 方法发送数据
        ws.send('Holle')
        console.log('ho');
    }
    ws.onmessage = (val) => {
        store.commit("SET_MESSAGE_VALUE", JSON.parse(val.data))
    }
    ws.onclose = () => {
        console.log('close');
        // 关闭 websocket
    }
    // 路由跳转时结束websocket链接
    // this.$router.afterEach(function () {
    //   ws.close()
    // })
}
